#ifndef _VIRTUAL_FILE_H_
#define _VIRTUAL_FILE_H_

#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/categories.hpp>
#include <boost/iostreams/positioning.hpp>

namespace PhysFS {

struct fileInfo
{
	inline fileInfo(const char* name, const char* mode="r+")
		:name(name),mode(mode)
	{}
	const char* name;
	const char* mode;
};

class device
{
public:
    typedef char         char_type;
	struct  category
		: boost::iostreams::seekable_device_tag,
		boost::iostreams::closable_tag,
		boost::iostreams::flushable_tag
	{};

	device(const fileInfo& info);

	~device();

    std::streamsize read(char* s, std::streamsize n);

    std::streamsize write(const char* s, std::streamsize n);

    boost::iostreams::stream_offset seek(boost::iostreams::stream_offset off, std::ios_base::seekdir way);

	boost::iostreams::stream_offset tell();

	std::streamsize size();

	bool eof();

	bool flush();

	void close();

private:
	void* file;
};

typedef boost::iostreams::stream<device> fstream;
class ofstream : public fstream
{
public:
	inline ofstream(const char* name)
		:fstream(fileInfo(name,"w+"))
	{}
};

class ifstream : public fstream
{
public:
	inline ifstream(const char* name)
		:fstream(fileInfo(name,"r+"))
	{}
};

}

#endif